package com.mec.fileTransfer.core;

import java.util.ArrayList;
import java.util.List;

public class TestSender {

	public static void main(String[] args) {
		String absolutePath = "F:\\testFileTransferSender\\";
		try {
			String filePath;
			int length;
			ReceiveFileSet fileSet = new ReceiveFileSet();
			ReceiveFileModel file;
			List<SendFileModel> fileList = new ArrayList<>();
//
//			filePath = "video\\1.png";
//			file = new ReceiveFileModel(filePath, 1888256, absolutePath);
//			fileSet.addFile(2, file);
//			long offset = 0;
//			length = 1888256;
//			fileList.add(new SendFileModel()
//					.setAbsoluteRootPath(absolutePath)
//					.setFilePath(filePath)
//					.setOffset(0)
//					.setLength(1888256));
//
//			filePath = "video\\2.png";
//			file = new ReceiveFileModel(filePath, 2048097, absolutePath);
//			fileSet.addFile(3, file);
//			fileList.add(new SendFileModel()
//					.setAbsoluteRootPath(absolutePath)
//					.setFilePath(filePath)
//					.setOffset(0)
//					.setLength(2048097));
			
			//手动将大文件分为几个Model进行并发传输
			filePath = "video\\tianfu.mp4";
			//526084217 500000000
			length = 526084217;
			file = new ReceiveFileModel(
					filePath, length, absolutePath);
			fileSet.addFile(1, file);
			
			long offset = 0;
//			while (length > 0) {
//				int len = length > ResourceSender.BUFFER_SIZE
//						? ResourceSender.BUFFER_SIZE : length;
//				SendFileModel sendFile = new SendFileModel()
//						.setAbsoluteRootPath(absolutePath)
//						.setFilePath(filePath)
//						.setOffset(offset)
//						.setLength(len);
//				fileList.add(sendFile);
//				length -= len;
//				offset += len;
//			}
			SendFileModel sendFile = new SendFileModel()
					.setAbsoluteRootPath(absolutePath)
					.setFilePath(filePath)
					.setOffset(offset)
					.setLength(length);
			fileList.add(sendFile);
			
			
//
//			filePath = "video\\3.png";
//			file = new ReceiveFileModel(filePath, 2048097, absolutePath);
//			fileSet.addFile(4, file);
//			fileList.add(new SendFileModel()
//					.setAbsoluteRootPath(absolutePath)
//					.setFilePath(filePath)
//					.setOffset(0)
//					.setLength(2048097));
//
//			filePath = "video\\4.jpg";
//			file = new ReceiveFileModel(filePath, 631025, absolutePath);
//			fileSet.addFile(5, file);
//			fileList.add(new SendFileModel()
//					.setAbsoluteRootPath(absolutePath)
//					.setFilePath(filePath)
//					.setOffset(0)
//					.setLength(631025));
//
//			filePath = "video\\5.jpg";
//			file = new ReceiveFileModel(filePath, 176010, absolutePath);
//			fileSet.addFile(6, file);
//			fileList.add(new SendFileModel()
//					.setAbsoluteRootPath(absolutePath)
//					.setFilePath(filePath)
//					.setOffset(0)
//					.setLength(176010));
			//产生发送中心对象，并进行启动
			ResourceSenderCenter senderCenter = new ResourceSenderCenter(
					"192.168.137.1", 54189);
			senderCenter.setSendFileSet(fileSet);
			senderCenter.setSendFileList(fileList);
			senderCenter.startSendding();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
